package com.oocl.hgl.crm.entity;

import com.oocl.hgl.crm.util.AppHelper;


public class Person implements Comparable{
	public static int currentId = -1;
	
	private int id;
	private String name;
	private int gender; //0,男  1,女 默认0
	private long birthday;
	private String address;
	private String phone;
	
	public static final int COMPARE_BY_ID = 0;
	public static final int COMPARE_BY_NAME = 1;
	
	public static final String DATE_FORMAT = "yyyy-MM-dd";
	
	public static int sort = -1;
	
	public String getBirthdayView(){
		return AppHelper.getBirthday(birthday, Person.DATE_FORMAT);
	}
	public String getGenderView(){
		String[] gArr = {"male","female"};
		if(gender==0 || gender==1 ){
			return gArr[gender];
		}
		return "?";
	}
	public String getView() {
		return "Person id=" + id + "\t name=" + name + "\t gender=" + getGenderView()
				+ "\t birthday=" + getBirthdayView() + "\t address=" + address
				+ "\t phone=" + phone ;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Person other = (Person) obj;
		if (id != other.id)
			return false;
		return true;
	}

	public static int getSort() {
		return sort;
	}
	public static void setSort(int sort) {
		Person.sort = sort;
	}
	@Override
	public String toString() {
		return "Person id=" + id + "\t name=" + name + "\t gender=" + gender
				+ "\t birthday=" + birthday + "\t address=" + address
				+ "\t phone=" + phone ;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	public Person(int id,String name, int gender, long birthday,
			String address, String phoneNumber) {
		super();
//		PersonInfoStorer.updateCurrentId();
//		this.id = currentId;
		this.id = id;
		this.name = name;
		this.gender = gender;
		this.birthday = birthday;
		this.address = address;
		this.phone = phoneNumber;
	}
	
	public Person() {}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getGender() {
		return gender;
	}
	public void setGender(int gender) {
		this.gender = gender;
	}
	public long getBirthday() {
		return birthday;
	}
	public void setBirthday(long birthday) {
		this.birthday = birthday;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public int compareTo(Object o) {
		if(sort==Person.COMPARE_BY_ID){
			return this.getId() - ((Person)o).getId();
		}
		if(sort==Person.COMPARE_BY_NAME){
			return this.getName().compareTo(((Person)o).getName());
		}
		return 0;
	}
}
